#!/bin/bash

set -e

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$PROJECT_ROOT"

echo "=========================================="
echo "Flink Agents 测试环境"
echo "=========================================="

# 检查是否已有镜像
if docker images | grep -q "browse-etl-flink-agents-test"; then
    echo "✅ 发现已有镜像"
    read -p "是否重新构建镜像？(y/N) " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        echo "🔨 重新构建镜像..."
        docker build -f tests/Dockerfile.flink-agents-test -t browse-etl-flink-agents-test tests/
    fi
else
    echo "🔨 首次构建镜像（需要 10-20 分钟）..."
    docker build -f tests/Dockerfile.flink-agents-test -t browse-etl-flink-agents-test tests/
fi

echo ""
echo "🧪 运行 Flink Agents 测试..."
echo ""

docker run --rm \
    browse-etl-flink-agents-test

echo ""
echo "=========================================="
echo "测试完成！"
echo "=========================================="

